package com.xm.design_patterns;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * Author：xm
 * Project：interview
 * Date：2025/8/4  18:42
 */

public class _023_HolderSingletonTest {
    public static void main(String[] args) {
        // System.out.println(_023_HolderSingleton.getInstance());
        System.out.println("Hello World");

        Set<String> set = Collections.synchronizedSet(new HashSet<String>());

        for (int i = 0; i < 10; i++) {
            // System.out.println(i);
            // new Thread(() -> set.add(_023_HolderSingleton.getInstance().toString())).start();

            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName());
                    set.add(_023_HolderSingleton.getInstance().toString());
                }
            });
            thread.start();
            // try {
            //     thread.join();
            // } catch (InterruptedException e) {
            //     throw new RuntimeException(e);
            // }
        }
        System.out.println(set.size());
        System.out.println(set);
    }
}
